<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html lang="en">

<head>
  <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
  <title>LCOV - iris.info - randomNumbers/impl/rng.cpp</title>
  <link rel="stylesheet" type="text/css" href="../../gcov.css">
</head>

<body>

  <table width="100%" border=0 cellspacing=0 cellpadding=0>
    <tr><td class="title">LTP GCOV extension - code coverage report</td></tr>
    <tr><td class="ruler"><img src="../../glass.png" width=3 height=3 alt=""></td></tr>

    <tr>
      <td width="100%">
        <table cellpadding=1 border=0 width="100%">
        <tr>
          <td class="headerItem" width="20%">Current&nbsp;view:</td>
          <td class="headerValue" width="80%" colspan=4><a href="../../index.html">directory</a> - <a href="index.html">randomNumbers/impl</a> - rng.cpp</td>
        </tr>
        <tr>
          <td class="headerItem" width="20%">Test:</td>
          <td class="headerValue" width="80%" colspan=4>iris.info</td>
        </tr>
        <tr>
          <td class="headerItem" width="20%">Date:</td>
          <td class="headerValue" width="20%">2010-05-24</td>
          <td width="20%"></td>
          <td class="headerItem" width="20%">Instrumented&nbsp;lines:</td>
          <td class="headerValue" width="20%">187</td>
        </tr>
        <tr>
          <td class="headerItem" width="20%">Code&nbsp;covered:</td>
          <td class="headerValue" width="20%">0.5 %</td>
          <td width="20%"></td>
          <td class="headerItem" width="20%">Executed&nbsp;lines:</td>
          <td class="headerValue" width="20%">1</td>
        </tr>
        </table>
      </td>
    </tr>
    <tr><td class="ruler"><img src="../../glass.png" width=3 height=3 alt=""></td></tr>
  </table>

  <table cellpadding=0 cellspacing=0 border=0>
    <tr>
      <td><br></td>
    </tr>
    <tr>
      <td><pre class="source">
<span class="lineNum">       1 </span>                : // GENERAL PUBLIC LICENSE AGREEMENT
<span class="lineNum">       2 </span>                : // 
<span class="lineNum">       3 </span>                : // PLEASE READ THIS DOCUMENT CAREFULLY BEFORE UTILIZING THE PROGRAM
<span class="lineNum">       4 </span>                : // 
<span class="lineNum">       5 </span>                : // BY UTILIZING THIS PROGRAM, YOU AGREE TO BECOME BOUND BY THE TERMS OF
<span class="lineNum">       6 </span>                : // THIS LICENSE.  IF YOU DO NOT AGREE TO THE TERMS OF THIS LICENSE, DO
<span class="lineNum">       7 </span>                : // NOT USE THIS PROGRAM OR ANY PORTION THEREOF IN ANY FORM OR MANNER.
<span class="lineNum">       8 </span>                : // 
<span class="lineNum">       9 </span>                : // This Program is licensed, not sold to you by GEORGIA TECH RESEARCH
<span class="lineNum">      10 </span>                : // CORPORATION (&quot;GTRC&quot;), owner of all code and accompanying documentation
<span class="lineNum">      11 </span>                : // (hereinafter &quot;Program&quot;), for use only under the terms of this License,
<span class="lineNum">      12 </span>                : // and GTRC reserves any rights not expressly granted to you.
<span class="lineNum">      13 </span>                : // 
<span class="lineNum">      14 </span>                : // 1.  This License allows you to:
<span class="lineNum">      15 </span>                : // 
<span class="lineNum">      16 </span>                : // (a) make copies and distribute copies of the Program's source code
<span class="lineNum">      17 </span>                : // provide that any such copy clearly displays any and all appropriate
<span class="lineNum">      18 </span>                : // copyright notices and disclaimer of warranty as set forth in Article 5
<span class="lineNum">      19 </span>                : // and 6 of this License.  All notices that refer to this License and to
<span class="lineNum">      20 </span>                : // the absence of any warranty must be kept intact at all times.  A copy
<span class="lineNum">      21 </span>                : // of this License must accompany any and all copies of the Program
<span class="lineNum">      22 </span>                : // distributed to third parties.
<span class="lineNum">      23 </span>                : // 
<span class="lineNum">      24 </span>                : // A fee may be charged to cover the cost associated with the physical
<span class="lineNum">      25 </span>                : // act of transferring a copy to a third party.  At no time shall the
<span class="lineNum">      26 </span>                : // program be sold for commercial gain either alone or incorporated with
<span class="lineNum">      27 </span>                : // other program(s) without entering into a separate agreement with GTRC.
<span class="lineNum">      28 </span>                : //  
<span class="lineNum">      29 </span>                : // 
<span class="lineNum">      30 </span>                : // (b) modify the original copy or copies of the Program or any portion
<span class="lineNum">      31 </span>                : // thereof (&quot;Modification(s)&quot;).  Modifications may be copied and
<span class="lineNum">      32 </span>                : // distributed under the terms and conditions as set forth above,
<span class="lineNum">      33 </span>                : // provided the following conditions are met:
<span class="lineNum">      34 </span>                : // 
<span class="lineNum">      35 </span>                : //     i) any and all modified files must be affixed with prominent
<span class="lineNum">      36 </span>                : // notices that you have changed the files and the date that the changes
<span class="lineNum">      37 </span>                : // occurred.
<span class="lineNum">      38 </span>                : //              
<span class="lineNum">      39 </span>                : //     ii) any work that you distribute, publish, or make available, that
<span class="lineNum">      40 </span>                : // in whole or in part contains portions of the Program or derivative
<span class="lineNum">      41 </span>                : // work thereof, must be licensed at no charge to all third parties under
<span class="lineNum">      42 </span>                : // the terms of this License.
<span class="lineNum">      43 </span>                : // 
<span class="lineNum">      44 </span>                : //    iii) if the modified program normally reads commands interactively
<span class="lineNum">      45 </span>                : // when run, you must cause it, when started running for such interactive
<span class="lineNum">      46 </span>                : // use in the most ordinary way, to display and/or print an announcement
<span class="lineNum">      47 </span>                : // with all appropriate copyright notices and disclaimer of warranty as
<span class="lineNum">      48 </span>                : // set forth in Article 5 and 6 of this License to be clearly displayed.
<span class="lineNum">      49 </span>                : // In addition, you must provide reasonable access to this License to the
<span class="lineNum">      50 </span>                : // user.
<span class="lineNum">      51 </span>                : // 
<span class="lineNum">      52 </span>                : // Any portion of a Modification that can be reasonably considered
<span class="lineNum">      53 </span>                : // independent of the Program and separate work in and of itself is not
<span class="lineNum">      54 </span>                : // subject to the terms and conditions set forth in this License as long
<span class="lineNum">      55 </span>                : // as it is not distributed with the Program or any portion thereof.
<span class="lineNum">      56 </span>                : // 
<span class="lineNum">      57 </span>                : // 
<span class="lineNum">      58 </span>                : // 2. This License further allows you to copy and distribute the Program
<span class="lineNum">      59 </span>                : //    or a work based on it, as set forth in Article 1 Section b in
<span class="lineNum">      60 </span>                : //    object code or executable form under the terms of Article 1 above
<span class="lineNum">      61 </span>                : //    provided that you also either:
<span class="lineNum">      62 </span>                : // 
<span class="lineNum">      63 </span>                : //    i) accompany it with complete corresponding machine-readable source
<span class="lineNum">      64 </span>                : // code, which must be distributed under the terms of Article 1, on a
<span class="lineNum">      65 </span>                : // medium customarily used for software interchange; or,
<span class="lineNum">      66 </span>                : // 
<span class="lineNum">      67 </span>                : //   ii) accompany it with a written offer, valid for no less than three
<span class="lineNum">      68 </span>                : // (3) years from the time of distribution, to give any third party, for
<span class="lineNum">      69 </span>                : // no consideration greater than the cost of physical transfer, a
<span class="lineNum">      70 </span>                : // complete machine-readable copy of the corresponding source code, to be
<span class="lineNum">      71 </span>                : // distributed under the terms of Article 1 on a medium customarily used
<span class="lineNum">      72 </span>                : // for software interchange; or,
<span class="lineNum">      73 </span>                : // 
<span class="lineNum">      74 </span>                : // 
<span class="lineNum">      75 </span>                : // 3.  Export Law Assurance.
<span class="lineNum">      76 </span>                : // 
<span class="lineNum">      77 </span>                : // You agree that the Software will not be shipped, transferred or
<span class="lineNum">      78 </span>                : // exported, directly into any country prohibited by the United States
<span class="lineNum">      79 </span>                : // Export Administration Act and the regulations thereunder nor will be
<span class="lineNum">      80 </span>                : // used for any purpose prohibited by the Act.
<span class="lineNum">      81 </span>                : //  
<span class="lineNum">      82 </span>                : // 4.  Termination.
<span class="lineNum">      83 </span>                : // 
<span class="lineNum">      84 </span>                : // If at anytime you are unable to comply with any portion of this
<span class="lineNum">      85 </span>                : // License you must immediately cease use of the Program and all
<span class="lineNum">      86 </span>                : // distribution activities involving the Program or any portion thereof.
<span class="lineNum">      87 </span>                : // 
<span class="lineNum">      88 </span>                : // 
<span class="lineNum">      89 </span>                : // 5.  Disclaimer of Warranties and Limitation on Liability.
<span class="lineNum">      90 </span>                : // 
<span class="lineNum">      91 </span>                : // YOU ACCEPT THE PROGRAM ON AN &quot;AS IS&quot; BASIS.  GTRC MAKES NO WARRANTY
<span class="lineNum">      92 </span>                : // THAT ALL ERRORS CAN BE OR HAVE BEEN ELIMINATED FROM PROGRAM.  GTRC
<span class="lineNum">      93 </span>                : // SHALL NOT BE RESPONSIBLE FOR LOSSES OF ANY KIND RESULTING FROM THE USE
<span class="lineNum">      94 </span>                : // OF PROGRAM AND ITS ACCOMPANYING DOCUMENT(S), AND CAN IN NO WAY PROVIDE
<span class="lineNum">      95 </span>                : // COMPENSATION FOR ANY LOSSES SUSTAINED, INCLUDING BUT NOT LIMITED TO
<span class="lineNum">      96 </span>                : // ANY OBLIGATION, LIABILITY, RIGHT, CLAIM OR REMEDY FOR TORT, OR FOR ANY
<span class="lineNum">      97 </span>                : // ACTUAL OR ALLEGED INFRINGEMENT OF PATENTS, COPYRIGHTS, TRADE SECRETS,
<span class="lineNum">      98 </span>                : // OR SIMILAR RIGHTS OF THIRD PARTIES, NOR ANY BUSINESS EXPENSE, MACHINE
<span class="lineNum">      99 </span>                : // DOWNTIME OR DAMAGES CAUSED TO YOU BY ANY DEFICIENCY, DEFECT OR ERROR
<span class="lineNum">     100 </span>                : // IN PROGRAM OR MALFUNCTION THEREOF, NOR ANY INCIDENTAL OR CONSEQUENTIAL
<span class="lineNum">     101 </span>                : // DAMAGES, HOWEVER CAUSED.  GTRC DISCLAIMS ALL WARRANTIES, BOTH EXPRESS
<span class="lineNum">     102 </span>                : // AND IMPLIED RESPECTING THE USE AND OPERATION OF PROGRAM AND ITS
<span class="lineNum">     103 </span>                : // ACCOMPANYING DOCUMENTATION, INCLUDING ALL IMPLIED WARRANTIES OF
<span class="lineNum">     104 </span>                : // MERCHANTABILITY AND FITNESS FOR PARTICULAR PURPOSE AND ANY IMPLIED
<span class="lineNum">     105 </span>                : // WARRANTY ARISING FROM COURSE OF PERFORMANCE, COURSE OF DEALING OR
<span class="lineNum">     106 </span>                : // USAGE OF TRADE.  GTRC MAKES NO WARRANTY THAT PROGRAM IS ADEQUATELY OR
<span class="lineNum">     107 </span>                : // COMPLETELY DESCRIBED IN, OR BEHAVES IN ACCORDANCE WITH ANY
<span class="lineNum">     108 </span>                : // ACCOMPANYING DOCUMENTATION.  THE USER OF PROGRAM IS EXPECTED TO MAKE
<span class="lineNum">     109 </span>                : // THE FINAL EVALUATION OF PROGRAM'S USEFULNESS IN USER'S OWN
<span class="lineNum">     110 </span>                : // ENVIRONMENT.
<span class="lineNum">     111 </span>                : // 
<span class="lineNum">     112 </span>                : // GTRC represents that, to the best of its knowledge, the software
<span class="lineNum">     113 </span>                : // furnished hereunder does not infringe any copyright or patent.
<span class="lineNum">     114 </span>                : // 
<span class="lineNum">     115 </span>                : // GTRC shall have no obligation for support or maintenance of Program.
<span class="lineNum">     116 </span>                : // 
<span class="lineNum">     117 </span>                : // 6.  Copyright Notice.
<span class="lineNum">     118 </span>                : // 
<span class="lineNum">     119 </span>                : // THE SOFTWARE AND ACCOMPANYING DOCUMENTATION ARE COPYRIGHTED WITH ALL
<span class="lineNum">     120 </span>                : // RIGHTS RESERVED BY GTRC.  UNDER UNITED STATES COPYRIGHT LAWS, THE
<span class="lineNum">     121 </span>                : // SOFTWARE AND ITS ACCOMPANYING DOCUMENTATION MAY NOT BE COPIED EXCEPT
<span class="lineNum">     122 </span>                : // AS GRANTED HEREIN.
<span class="lineNum">     123 </span>                : // 
<span class="lineNum">     124 </span>                : // You acknowledge that GTRC is the sole owner of Program, including all
<span class="lineNum">     125 </span>                : // copyrights subsisting therein.  Any and all copies or partial copies
<span class="lineNum">     126 </span>                : // of Program made by you shall bear the copyright notice set forth below
<span class="lineNum">     127 </span>                : // and affixed to the original version or such other notice as GTRC shall
<span class="lineNum">     128 </span>                : // designate.  Such notice shall also be affixed to all improvements or
<span class="lineNum">     129 </span>                : // enhancements of Program made by you or portions thereof in such a
<span class="lineNum">     130 </span>                : // manner and location as to give reasonable notice of GTRC's copyright
<span class="lineNum">     131 </span>                : // as set forth in Article 1.
<span class="lineNum">     132 </span>                : // 
<span class="lineNum">     133 </span>                : // Said copyright notice shall read as follows:
<span class="lineNum">     134 </span>                : // 
<span class="lineNum">     135 </span>                : // Copyright 2004
<span class="lineNum">     136 </span>                : // Dr. George F. Riley
<span class="lineNum">     137 </span>                : // Georgia Tech Research Corporation
<span class="lineNum">     138 </span>                : // Atlanta, Georgia 30332-0415
<span class="lineNum">     139 </span>                : // All Rights Reserved
<span class="lineNum">     140 </span>                : //
<span class="lineNum">     141 </span>                : // $Id: rng.cc,v 1.7 2006/01/31 20:48:39 riley Exp $
<span class="lineNum">     142 </span>                : 
<span class="lineNum">     143 </span>                : 
<span class="lineNum">     144 </span>                : 
<span class="lineNum">     145 </span>                : // Georgia Tech Network Simulator - Random Number class
<span class="lineNum">     146 </span>                : // George F. Riley.  Georgia Tech, Spring 2002
<span class="lineNum">     147 </span>                : 
<span class="lineNum">     148 </span>                : #include &lt;iostream&gt;
<span class="lineNum">     149 </span>                : 
<span class="lineNum">     150 </span>                : #include &lt;math.h&gt;
<span class="lineNum">     151 </span>                : #include &lt;stdlib.h&gt;
<span class="lineNum">     152 </span>                : #ifndef WIN32
<span class="lineNum">     153 </span>                : #include &lt;sys/time.h&gt;                     // for gettimeofday
<span class="lineNum">     154 </span>                : #include &lt;unistd.h&gt;
<span class="lineNum">     155 </span>                : #else
<span class="lineNum">     156 </span>                : #include &lt;time.h&gt;                 // for gettimeofday
<span class="lineNum">     157 </span>                : #include &lt;windows.h&gt;
<span class="lineNum">     158 </span>                : #include &lt;winsock.h&gt;
<span class="lineNum">     159 </span>                : #endif
<span class="lineNum">     160 </span>                : 
<span class="lineNum">     161 </span>                : #include &lt;iostream&gt;
<span class="lineNum">     162 </span>                : #include &lt;sys/types.h&gt;
<span class="lineNum">     163 </span>                : #include &lt;sys/stat.h&gt;
<span class="lineNum">     164 </span>                : #include &lt;fcntl.h&gt;       
<span class="lineNum">     165 </span>                : 
<span class="lineNum">     166 </span>                : //#define DEBUG_MASK 0x01
<span class="lineNum">     167 </span>                : #include &quot;debug.hpp&quot;
<span class="lineNum">     168 </span>                : #include &quot;rng.hpp&quot;
<span class="lineNum">     169 </span>                : 
<span class="lineNum">     170 </span>                : using namespace std;
<span class="lineNum">     171 </span>                : 
<span class="lineNum">     172 </span>                : // Seed methods
<span class="lineNum">     173 </span><span class="lineNoCov">              0 : ConstantSeed::ConstantSeed(Seed_t s)</span>
<span class="lineNum">     174 </span>                : {
<span class="lineNum">     175 </span><span class="lineNoCov">              0 :   seeds[0] = s;</span>
<span class="lineNum">     176 </span><span class="lineNoCov">              0 :   seeds[1] = s;</span>
<span class="lineNum">     177 </span><span class="lineNoCov">              0 :   seeds[2] = s;</span>
<span class="lineNum">     178 </span><span class="lineNoCov">              0 :   seeds[3] = s;</span>
<span class="lineNum">     179 </span><span class="lineNoCov">              0 :   seeds[4] = s;</span>
<span class="lineNum">     180 </span><span class="lineNoCov">              0 :   seeds[5] = s;</span>
<span class="lineNum">     181 </span><span class="lineNoCov">              0 : }</span>
<span class="lineNum">     182 </span>                : 
<span class="lineNum">     183 </span>                : ConstantSeed::ConstantSeed(Seed_t s0, Seed_t s1, Seed_t s2,
<span class="lineNum">     184 </span><span class="lineNoCov">              0 :                            Seed_t s3, Seed_t s4, Seed_t s5)</span>
<span class="lineNum">     185 </span>                : {
<span class="lineNum">     186 </span><span class="lineNoCov">              0 :   seeds[0] = s0;</span>
<span class="lineNum">     187 </span><span class="lineNoCov">              0 :   seeds[1] = s1;</span>
<span class="lineNum">     188 </span><span class="lineNoCov">              0 :   seeds[2] = s2;</span>
<span class="lineNum">     189 </span><span class="lineNoCov">              0 :   seeds[3] = s3;</span>
<span class="lineNum">     190 </span><span class="lineNoCov">              0 :   seeds[4] = s4;</span>
<span class="lineNum">     191 </span><span class="lineNoCov">              0 :   seeds[5] = s5;</span>
<span class="lineNum">     192 </span><span class="lineNoCov">              0 : }</span>
<span class="lineNum">     193 </span>                : 
<span class="lineNum">     194 </span>                : // Base class methods
<span class="lineNum">     195 </span>                : 
<span class="lineNum">     196 </span>                : bool          Random::useDevRandom = false;  // True if use /dev/random desired
<span class="lineNum">     197 </span>                : bool          Random::globalSeedSet = false; // True if GlobalSeed called
<span class="lineNum">     198 </span>                : int           Random::devRandom = -1;
<span class="lineNum">     199 </span>                : Seed_t        Random::globalSeed[6];
<span class="lineNum">     200 </span>                : unsigned long Random::heuristic_sequence;
<span class="lineNum">     201 </span>                : RngStream*    Random::globalRNG;
<span class="lineNum">     202 </span>                : 
<span class="lineNum">     203 </span><span class="lineNoCov">              0 : Random::Random() </span>
<span class="lineNum">     204 </span><span class="lineNoCov">              0 :     : privateStream(nil)</span>
<span class="lineNum">     205 </span>                : { // Nothing to be done here
<span class="lineNum">     206 </span>                :   DEBUG0((cout &lt;&lt; &quot;Hello from Random::Random()&quot; &lt;&lt; endl));
<span class="lineNum">     207 </span><span class="lineNoCov">              0 : }</span>
<span class="lineNum">     208 </span>                :   
<span class="lineNum">     209 </span><span class="lineNoCov">              0 : Random_t Random::Value()</span>
<span class="lineNum">     210 </span>                : {
<span class="lineNum">     211 </span><span class="lineNoCov">              0 :   Initialize();</span>
<span class="lineNum">     212 </span>                :   // Check if private stream, use it if so
<span class="lineNum">     213 </span><span class="lineNoCov">              0 :   if (privateStream) return privateStream-&gt;RandU01();</span>
<span class="lineNum">     214 </span>                :   // Otherwise use the common global one
<span class="lineNum">     215 </span><span class="lineNoCov">              0 :   return globalRNG-&gt;RandU01(); // Uniform [0..1)</span>
<span class="lineNum">     216 </span>                : }
<span class="lineNum">     217 </span>                : 
<span class="lineNum">     218 </span><span class="lineNoCov">              0 : Random* Random::Copy() const</span>
<span class="lineNum">     219 </span>                : {
<span class="lineNum">     220 </span><span class="lineNoCov">              0 :   return new Random(*this);</span>
<span class="lineNum">     221 </span>                : }
<span class="lineNum">     222 </span>                : 
<span class="lineNum">     223 </span><span class="lineNoCov">              0 : bool Random::SetSeed(const Seed&amp; s)</span>
<span class="lineNum">     224 </span>                : {
<span class="lineNum">     225 </span>                :     /* 
<span class="lineNum">     226 </span>                :   // Get a private stream for this generator if not already created
<span class="lineNum">     227 </span>                :   if (s.IsRandom())
<span class="lineNum">     228 </span>                :     {
<span class="lineNum">     229 </span>                :       Seed_t seeds[6];
<span class="lineNum">     230 </span>                :       GetRandomSeeds(seeds);
<span class="lineNum">     231 </span>                :       if (!privateStream) privateStream = new RngStream();
<span class="lineNum">     232 </span>                :       return privateStream-&gt;SetSeed(seeds);
<span class="lineNum">     233 </span>                :     }
<span class="lineNum">     234 </span>                :   // Not random seed, use specified
<span class="lineNum">     235 </span>                :   const ConstantSeed&amp; cs = (ConstantSeed&amp;)s;
<span class="lineNum">     236 </span>                :   if (!RngStream::CheckSeed(cs.seeds)) return false; // Seed is not valid
<span class="lineNum">     237 </span>                :   if (!privateStream) privateStream = new RngStream();
<span class="lineNum">     238 </span>                :   return privateStream-&gt;SetSeed(cs.seeds);
<span class="lineNum">     239 </span>                :      * */
<span class="lineNum">     240 </span><span class="lineNoCov">              0 : }</span>
<span class="lineNum">     241 </span>                : 
<span class="lineNum">     242 </span>                : // Uniform methods
<span class="lineNum">     243 </span><span class="lineNoCov">              0 : Random_t Uniform::Value()</span>
<span class="lineNum">     244 </span>                : {
<span class="lineNum">     245 </span><span class="lineNoCov">              0 :   return m_min + Random::Value() * (m_max - m_min);</span>
<span class="lineNum">     246 </span>                : }
<span class="lineNum">     247 </span>                : 
<span class="lineNum">     248 </span><span class="lineNoCov">              0 : Random* Uniform::Copy() const</span>
<span class="lineNum">     249 </span>                : {
<span class="lineNum">     250 </span><span class="lineNoCov">              0 :   return new Uniform(*this);</span>
<span class="lineNum">     251 </span>                : }
<span class="lineNum">     252 </span>                : 
<span class="lineNum">     253 </span>                : // Constant methods
<span class="lineNum">     254 </span><span class="lineNoCov">              0 : Random_t Constant::Value()</span>
<span class="lineNum">     255 </span>                : {
<span class="lineNum">     256 </span><span class="lineNoCov">              0 :   return m_const;</span>
<span class="lineNum">     257 </span>                : }
<span class="lineNum">     258 </span>                : 
<span class="lineNum">     259 </span><span class="lineNoCov">              0 : IRandom_t Constant::IntValue()</span>
<span class="lineNum">     260 </span>                : {
<span class="lineNum">     261 </span><span class="lineNoCov">              0 :   return (IRandom_t)m_const;</span>
<span class="lineNum">     262 </span>                : }
<span class="lineNum">     263 </span>                : 
<span class="lineNum">     264 </span><span class="lineNoCov">              0 : Random* Constant::Copy() const</span>
<span class="lineNum">     265 </span>                : {
<span class="lineNum">     266 </span><span class="lineNoCov">              0 :   return new Constant(*this);</span>
<span class="lineNum">     267 </span>                : }
<span class="lineNum">     268 </span>                : 
<span class="lineNum">     269 </span>                : // Sequential methods
<span class="lineNum">     270 </span><span class="lineNoCov">              0 : Sequential::Sequential(Random_t f, Random_t l, Random_t i, Count_t c)</span>
<span class="lineNum">     271 </span>                :   : m_min(f), m_max(l), m_increment(Constant(i).Copy()), m_consecutive(c),
<span class="lineNum">     272 </span><span class="lineNoCov">              0 :     m_current(f), m_currentConsecutive(0)</span>
<span class="lineNum">     273 </span>                : {
<span class="lineNum">     274 </span><span class="lineNoCov">              0 : }</span>
<span class="lineNum">     275 </span>                : 
<span class="lineNum">     276 </span><span class="lineNoCov">              0 : Sequential::Sequential(Random_t f, Random_t l, const Random&amp; i, Count_t c)</span>
<span class="lineNum">     277 </span>                :   : m_min(f), m_max(l), m_increment(i.Copy()), m_consecutive(c),
<span class="lineNum">     278 </span><span class="lineNoCov">              0 :     m_current(f), m_currentConsecutive(0)</span>
<span class="lineNum">     279 </span>                : {
<span class="lineNum">     280 </span><span class="lineNoCov">              0 : }</span>
<span class="lineNum">     281 </span>                : 
<span class="lineNum">     282 </span><span class="lineNoCov">              0 : Sequential::Sequential(const Sequential&amp; c)</span>
<span class="lineNum">     283 </span>                :   : m_min(c.m_min), m_max(c.m_max),
<span class="lineNum">     284 </span>                :     m_increment(c.m_increment-&gt;Copy()), m_consecutive(c.m_consecutive),
<span class="lineNum">     285 </span><span class="lineNoCov">              0 :     m_current(c.m_current), m_currentConsecutive(c.m_currentConsecutive)</span>
<span class="lineNum">     286 </span>                : {
<span class="lineNum">     287 </span><span class="lineNoCov">              0 : }</span>
<span class="lineNum">     288 </span>                : 
<span class="lineNum">     289 </span><span class="lineNoCov">              0 : Random_t Sequential::Value()</span>
<span class="lineNum">     290 </span>                : { // Return a sequential series of values
<span class="lineNum">     291 </span><span class="lineNoCov">              0 :   Random_t r = m_current;</span>
<span class="lineNum">     292 </span><span class="lineNoCov">              0 :   if (++m_currentConsecutive == m_consecutive)</span>
<span class="lineNum">     293 </span>                :     { // Time to advance to next
<span class="lineNum">     294 </span><span class="lineNoCov">              0 :       m_currentConsecutive = 0;</span>
<span class="lineNum">     295 </span><span class="lineNoCov">              0 :       m_current += m_increment-&gt;Value();</span>
<span class="lineNum">     296 </span><span class="lineNoCov">              0 :       if (m_current &gt;= m_max)</span>
<span class="lineNum">     297 </span><span class="lineNoCov">              0 :         m_current = m_min + (m_current - m_max);</span>
<span class="lineNum">     298 </span>                :     }
<span class="lineNum">     299 </span><span class="lineNoCov">              0 :   return r;</span>
<span class="lineNum">     300 </span>                : }
<span class="lineNum">     301 </span>                : 
<span class="lineNum">     302 </span><span class="lineNoCov">              0 : Random* Sequential::Copy() const</span>
<span class="lineNum">     303 </span>                : {
<span class="lineNum">     304 </span><span class="lineNoCov">              0 :   return new Sequential(*this);</span>
<span class="lineNum">     305 </span>                : }
<span class="lineNum">     306 </span>                : 
<span class="lineNum">     307 </span>                : // Exponential methods
<span class="lineNum">     308 </span><span class="lineNoCov">              0 : Random_t Exponential::Value()</span>
<span class="lineNum">     309 </span>                : {
<span class="lineNum">     310 </span><span class="lineNoCov">              0 :   Random_t r = -m_mean*log(Random::Value());</span>
<span class="lineNum">     311 </span><span class="lineNoCov">              0 :   if (m_bound != 0 &amp;&amp; r &gt; m_bound) return m_bound;</span>
<span class="lineNum">     312 </span><span class="lineNoCov">              0 :   return r;</span>
<span class="lineNum">     313 </span>                : }
<span class="lineNum">     314 </span>                : 
<span class="lineNum">     315 </span><span class="lineNoCov">              0 : Random* Exponential::Copy() const</span>
<span class="lineNum">     316 </span>                : {
<span class="lineNum">     317 </span><span class="lineNoCov">              0 :   return new Exponential(*this);</span>
<span class="lineNum">     318 </span>                : }
<span class="lineNum">     319 </span>                : 
<span class="lineNum">     320 </span>                : // Pareto methods
<span class="lineNum">     321 </span><span class="lineNoCov">              0 : Random_t Pareto::Value()</span>
<span class="lineNum">     322 </span>                : {
<span class="lineNum">     323 </span><span class="lineNoCov">              0 : Random_t scale = m_mean * ( m_shape - 1.0) / m_shape;</span>
<span class="lineNum">     324 </span>                : 
<span class="lineNum">     325 </span><span class="lineNoCov">              0 :   Random_t r = (scale * ( 1.0 / pow(Random::Value(), 1.0 / m_shape)));</span>
<span class="lineNum">     326 </span>                :   DEBUG0((cout &lt;&lt; &quot;Pareto, scale &quot; &lt;&lt; scale &lt;&lt; &quot; r &quot; &lt;&lt; r &lt;&lt; endl));
<span class="lineNum">     327 </span><span class="lineNoCov">              0 :   if (m_bound != 0 &amp;&amp; r &gt; m_bound) return m_bound;</span>
<span class="lineNum">     328 </span><span class="lineNoCov">              0 :   return r;</span>
<span class="lineNum">     329 </span>                : }
<span class="lineNum">     330 </span>                : 
<span class="lineNum">     331 </span><span class="lineNoCov">              0 : Random* Pareto::Copy() const</span>
<span class="lineNum">     332 </span>                : {
<span class="lineNum">     333 </span><span class="lineNoCov">              0 :   return new Pareto(*this);</span>
<span class="lineNum">     334 </span>                : }
<span class="lineNum">     335 </span>                : 
<span class="lineNum">     336 </span>                : // Weibull methods
<span class="lineNum">     337 </span><span class="lineNoCov">              0 : Random_t Weibull::Value()</span>
<span class="lineNum">     338 </span>                : {
<span class="lineNum">     339 </span><span class="lineNoCov">              0 : Random_t exponent = 1.0 / m_alpha;</span>
<span class="lineNum">     340 </span>                : 
<span class="lineNum">     341 </span><span class="lineNoCov">              0 :   Random_t r = m_mean * pow( -log(Random::Value()), exponent);</span>
<span class="lineNum">     342 </span><span class="lineNoCov">              0 :   if (m_bound != 0 &amp;&amp; r &gt; m_bound) return m_bound;</span>
<span class="lineNum">     343 </span><span class="lineNoCov">              0 :   return r;</span>
<span class="lineNum">     344 </span>                : }
<span class="lineNum">     345 </span>                : 
<span class="lineNum">     346 </span><span class="lineNoCov">              0 : Random* Weibull::Copy() const</span>
<span class="lineNum">     347 </span>                : {
<span class="lineNum">     348 </span><span class="lineNoCov">              0 :   return new Weibull(*this);</span>
<span class="lineNum">     349 </span>                : }
<span class="lineNum">     350 </span>                : 
<span class="lineNum">     351 </span>                : // Normal methods
<span class="lineNum">     352 </span><span class="lineNoCov">              0 : Random_t Normal::Value()</span>
<span class="lineNum">     353 </span>                : {
<span class="lineNum">     354 </span><span class="lineNoCov">              0 :   if (m_nextValid)</span>
<span class="lineNum">     355 </span>                :     { // use previously generated
<span class="lineNum">     356 </span><span class="lineNoCov">              0 :       m_nextValid = false;</span>
<span class="lineNum">     357 </span><span class="lineNoCov">              0 :       return m_next;</span>
<span class="lineNum">     358 </span>                :     }
<span class="lineNum">     359 </span>                :   while(1)
<span class="lineNum">     360 </span>                :     { // See Simulation Modeling and Analysis p. 466 (Averill Law)
<span class="lineNum">     361 </span>                :       // for algorithm
<span class="lineNum">     362 </span><span class="lineNoCov">              0 :       Random_t u1 = Random::Value();</span>
<span class="lineNum">     363 </span><span class="lineNoCov">              0 :       Random_t u2 = Random::Value();</span>
<span class="lineNum">     364 </span><span class="lineNoCov">              0 :       Random_t v1 = 2 * u1 - 1;</span>
<span class="lineNum">     365 </span><span class="lineNoCov">              0 :       Random_t v2 = 2 * u2 - 1;</span>
<span class="lineNum">     366 </span><span class="lineNoCov">              0 :       Random_t w = v1 * v1 + v2 * v2;</span>
<span class="lineNum">     367 </span><span class="lineNoCov">              0 :       if (w &lt;= 1.0)</span>
<span class="lineNum">     368 </span>                :         { // Got good pair
<span class="lineNum">     369 </span><span class="lineNoCov">              0 :           Random_t y = sqrt((-2 * log(w))/w);</span>
<span class="lineNum">     370 </span><span class="lineNoCov">              0 :           m_next = m_mean + v2 * y * sqrt(m_variance);</span>
<span class="lineNum">     371 </span><span class="lineNoCov">              0 :           if (fabs(m_next) &gt; m_bound) m_next = m_bound * (m_next)/fabs(m_next);</span>
<span class="lineNum">     372 </span><span class="lineNoCov">              0 :           m_nextValid = true;</span>
<span class="lineNum">     373 </span><span class="lineNoCov">              0 :           Random_t x1 = m_mean + v1 * y * sqrt(m_variance);</span>
<span class="lineNum">     374 </span><span class="lineNoCov">              0 :           if (fabs(x1) &gt; m_bound) x1 = m_bound * (x1)/fabs(x1);</span>
<span class="lineNum">     375 </span><span class="lineNoCov">              0 :           return x1;</span>
<span class="lineNum">     376 </span>                :         }
<span class="lineNum">     377 </span>                :     }
<span class="lineNum">     378 </span>                : }
<span class="lineNum">     379 </span>                : 
<span class="lineNum">     380 </span><span class="lineNoCov">              0 : Random* Normal::Copy() const</span>
<span class="lineNum">     381 </span>                : {
<span class="lineNum">     382 </span><span class="lineNoCov">              0 :   return new Normal(*this);</span>
<span class="lineNum">     383 </span>                : }
<span class="lineNum">     384 </span>                : 
<span class="lineNum">     385 </span>                : // Empirical methods
<span class="lineNum">     386 </span><span class="lineNoCov">              0 : Random_t Empirical::Value()</span>
<span class="lineNum">     387 </span>                : { // Return a value from the empirical distribution
<span class="lineNum">     388 </span>                :   // This code based (loosely) on code by Bruce Mah (Thanks Bruce!)
<span class="lineNum">     389 </span><span class="lineNoCov">              0 :   if (emp.size() == 0) return 0.0; // HuH? No empirical data</span>
<span class="lineNum">     390 </span><span class="lineNoCov">              0 :   if (!validated) Validate();      // Insure in non-decreasing</span>
<span class="lineNum">     391 </span><span class="lineNoCov">              0 :   Random_t r = Random::Value();</span>
<span class="lineNum">     392 </span><span class="lineNoCov">              0 :   if (r &lt;= emp.front().cdf)return emp.front().value; // Less than first</span>
<span class="lineNum">     393 </span><span class="lineNoCov">              0 :   if (r &gt;= emp.back().cdf) return emp.back().value;  // Greater than last</span>
<span class="lineNum">     394 </span>                :   // Binary search
<span class="lineNum">     395 </span><span class="lineNoCov">              0 :   ValueCDFVec_t::size_type bottom = 0;</span>
<span class="lineNum">     396 </span><span class="lineNoCov">              0 :   ValueCDFVec_t::size_type top = emp.size() - 1;</span>
<span class="lineNum">     397 </span>                :   while(1)
<span class="lineNum">     398 </span>                :     {
<span class="lineNum">     399 </span><span class="lineNoCov">              0 :       ValueCDFVec_t::size_type c = (top + bottom) / 2;</span>
<span class="lineNum">     400 </span><span class="lineNoCov">              0 :       if (r &gt;= emp[c].cdf &amp;&amp; r &lt; emp[c+1].cdf)</span>
<span class="lineNum">     401 </span>                :         { // Found it
<span class="lineNum">     402 </span>                :           return Interpolate(emp[c].cdf, emp[c+1].cdf,
<span class="lineNum">     403 </span>                :                              emp[c].value, emp[c+1].value,
<span class="lineNum">     404 </span><span class="lineNoCov">              0 :                              r);</span>
<span class="lineNum">     405 </span>                :         }
<span class="lineNum">     406 </span>                :       // Not here, adjust bounds
<span class="lineNum">     407 </span><span class="lineNoCov">              0 :       if (r &lt; emp[c].cdf) top    = c - 1;</span>
<span class="lineNum">     408 </span><span class="lineNoCov">              0 :       else                bottom = c + 1;</span>
<span class="lineNum">     409 </span>                :     }
<span class="lineNum">     410 </span>                : }
<span class="lineNum">     411 </span>                : 
<span class="lineNum">     412 </span><span class="lineNoCov">              0 : Random* Empirical::Copy() const</span>
<span class="lineNum">     413 </span>                : {
<span class="lineNum">     414 </span><span class="lineNoCov">              0 :   return new Empirical(*this);</span>
<span class="lineNum">     415 </span>                : }
<span class="lineNum">     416 </span>                : 
<span class="lineNum">     417 </span><span class="lineNoCov">              0 : void Empirical::CDF(Random_t v, CDF_t c)</span>
<span class="lineNum">     418 </span>                : { // Add a new empirical datapoint to the empirical cdf
<span class="lineNum">     419 </span>                :   // NOTE.   These MUST be inserted in non-decreasing order
<span class="lineNum">     420 </span><span class="lineNoCov">              0 :   emp.push_back(ValueCDF(v, c));</span>
<span class="lineNum">     421 </span><span class="lineNoCov">              0 : }</span>
<span class="lineNum">     422 </span>                : 
<span class="lineNum">     423 </span><span class="lineNoCov">              0 : void Empirical::Validate()</span>
<span class="lineNum">     424 </span>                : {
<span class="lineNum">     425 </span>                :   ValueCDF prior;
<span class="lineNum">     426 </span><span class="lineNoCov">              0 :   for (ValueCDFVec_t::size_type i = 0; i &lt; emp.size(); ++i)</span>
<span class="lineNum">     427 </span>                :     {
<span class="lineNum">     428 </span><span class="lineNoCov">              0 :       ValueCDF&amp; current = emp[i];</span>
<span class="lineNum">     429 </span><span class="lineNoCov">              0 :       if (current.value &lt; prior.value || current.cdf &lt; prior.cdf)</span>
<span class="lineNum">     430 </span>                :         { // Error
<span class="lineNum">     431 </span>                :           cout &lt;&lt; &quot;Empirical Dist error,&quot;
<span class="lineNum">     432 </span>                :                &lt;&lt; &quot; current value &quot; &lt;&lt; current.value
<span class="lineNum">     433 </span>                :                &lt;&lt; &quot; prior value &quot;   &lt;&lt; prior.value
<span class="lineNum">     434 </span>                :                &lt;&lt; &quot; current cdf &quot;   &lt;&lt; current.cdf
<span class="lineNum">     435 </span><span class="lineNoCov">              0 :                &lt;&lt; &quot; prior cdf &quot;     &lt;&lt; prior.cdf &lt;&lt; endl;</span>
<span class="lineNum">     436 </span><span class="lineNoCov">              0 :           exit(1);</span>
<span class="lineNum">     437 </span>                :         }
<span class="lineNum">     438 </span><span class="lineNoCov">              0 :       prior = current;</span>
<span class="lineNum">     439 </span>                :     }
<span class="lineNum">     440 </span><span class="lineNoCov">              0 :   validated = true;</span>
<span class="lineNum">     441 </span><span class="lineNoCov">              0 : }</span>
<span class="lineNum">     442 </span>                : 
<span class="lineNum">     443 </span>                : Random_t Empirical::Interpolate(CDF_t c1, CDF_t c2,
<span class="lineNum">     444 </span><span class="lineNoCov">              0 :                                 Random_t v1, Random_t v2, CDF_t r)</span>
<span class="lineNum">     445 </span>                : { // Interpolate random value in range [v1..v2) based on [c1 .. r .. c2)
<span class="lineNum">     446 </span><span class="lineNoCov">              0 :   return (v1 + ((v2 - v1) / (c2 - c1)) * (r - c1));</span>
<span class="lineNum">     447 </span>                : }
<span class="lineNum">     448 </span>                : 
<span class="lineNum">     449 </span>                : // Integer Empirical methods
<span class="lineNum">     450 </span>                : 
<span class="lineNum">     451 </span><span class="lineNoCov">              0 : IRandom_t IntEmpirical::IntValue()</span>
<span class="lineNum">     452 </span>                : {
<span class="lineNum">     453 </span><span class="lineNoCov">              0 :   return (IRandom_t)Value();</span>
<span class="lineNum">     454 </span>                : }
<span class="lineNum">     455 </span>                : 
<span class="lineNum">     456 </span><span class="lineNoCov">              0 : Random* IntEmpirical::Copy() const</span>
<span class="lineNum">     457 </span>                : {
<span class="lineNum">     458 </span><span class="lineNoCov">              0 :   return new IntEmpirical(*this);</span>
<span class="lineNum">     459 </span>                : }
<span class="lineNum">     460 </span>                : 
<span class="lineNum">     461 </span>                : 
<span class="lineNum">     462 </span>                : Random_t IntEmpirical::Interpolate(CDF_t c1, CDF_t c2,
<span class="lineNum">     463 </span><span class="lineNoCov">              0 :                                    Random_t v1, Random_t v2, CDF_t r)</span>
<span class="lineNum">     464 </span>                : { // Interpolate random value in range [v1..v2) based on [c1 .. r .. c2)
<span class="lineNum">     465 </span><span class="lineNoCov">              0 :   return ceil(v1 + ((v2 - v1) / (c2 - c1)) * (r - c1));</span>
<span class="lineNum">     466 </span>                : }
<span class="lineNum">     467 </span>                : 
<span class="lineNum">     468 </span>                : // Deterministic
<span class="lineNum">     469 </span><span class="lineNoCov">              0 : Deterministic::Deterministic(Random_t* d, Count_t c)</span>
<span class="lineNum">     470 </span><span class="lineNoCov">              0 :     : count(c), next(c), data(d)</span>
<span class="lineNum">     471 </span>                : { // Nothing else needed
<span class="lineNum">     472 </span><span class="lineNoCov">              0 : }</span>
<span class="lineNum">     473 </span>                : 
<span class="lineNum">     474 </span>                :   
<span class="lineNum">     475 </span><span class="lineNoCov">              0 : Random_t Deterministic::Value()</span>
<span class="lineNum">     476 </span>                : {
<span class="lineNum">     477 </span><span class="lineNoCov">              0 :   if (next == count) next = 0;</span>
<span class="lineNum">     478 </span><span class="lineNoCov">              0 :   return data[next++];</span>
<span class="lineNum">     479 </span>                : }
<span class="lineNum">     480 </span>                : 
<span class="lineNum">     481 </span><span class="lineNoCov">              0 : Random* Deterministic::Copy() const</span>
<span class="lineNum">     482 </span>                : {
<span class="lineNum">     483 </span><span class="lineNoCov">              0 :   return new Deterministic(*this);</span>
<span class="lineNum">     484 </span>                : }
<span class="lineNum">     485 </span>                : 
<span class="lineNum">     486 </span>                : // Static Methods
<span class="lineNum">     487 </span>                : bool Random::GlobalSeed(Seed_t s0, Seed_t s1, Seed_t s2,
<span class="lineNum">     488 </span><span class="lineNoCov">              0 :                 Seed_t s3, Seed_t s4, Seed_t s5)</span>
<span class="lineNum">     489 </span>                : {
<span class="lineNum">     490 </span><span class="lineNoCov">              0 :   if (globalRNG)</span>
<span class="lineNum">     491 </span>                :     {
<span class="lineNum">     492 </span><span class="lineNoCov">              0 :       cout &lt;&lt; &quot;Random number generator already initialized!&quot; &lt;&lt; endl;</span>
<span class="lineNum">     493 </span><span class="lineNoCov">              0 :       cout &lt;&lt; &quot;Call to Random::GlobalSeed() ignored&quot; &lt;&lt; endl;</span>
<span class="lineNum">     494 </span><span class="lineNoCov">              0 :       return false;</span>
<span class="lineNum">     495 </span>                :     }
<span class="lineNum">     496 </span><span class="lineNoCov">              0 :   globalSeed[0] = s0;</span>
<span class="lineNum">     497 </span><span class="lineNoCov">              0 :   globalSeed[1] = s1;</span>
<span class="lineNum">     498 </span><span class="lineNoCov">              0 :   globalSeed[2] = s2;</span>
<span class="lineNum">     499 </span><span class="lineNoCov">              0 :   globalSeed[3] = s3;</span>
<span class="lineNum">     500 </span><span class="lineNoCov">              0 :   globalSeed[4] = s4;</span>
<span class="lineNum">     501 </span><span class="lineNoCov">              0 :   globalSeed[5] = s5;</span>
<span class="lineNum">     502 </span><span class="lineNoCov">              0 :   if (!RngStream::CheckSeed(globalSeed)) return false; // Invalid  seed</span>
<span class="lineNum">     503 </span><span class="lineNoCov">              0 :   globalSeedSet = true;</span>
<span class="lineNum">     504 </span><span class="lineNoCov">              0 :   return true;</span>
<span class="lineNum">     505 </span>                : }
<span class="lineNum">     506 </span>                : 
<span class="lineNum">     507 </span><span class="lineNoCov">              0 : bool Random::GlobalSeed(const Seed&amp; s)</span>
<span class="lineNum">     508 </span>                : {
<span class="lineNum">     509 </span><span class="lineNoCov">              0 :   if (globalRNG)</span>
<span class="lineNum">     510 </span>                :     {
<span class="lineNum">     511 </span><span class="lineNoCov">              0 :       cout &lt;&lt; &quot;Random number generator already initialized!&quot; &lt;&lt; endl;</span>
<span class="lineNum">     512 </span><span class="lineNoCov">              0 :       cout &lt;&lt; &quot;Call to Random::GlobalSeed() ignored&quot; &lt;&lt; endl;</span>
<span class="lineNum">     513 </span><span class="lineNoCov">              0 :       return false;</span>
<span class="lineNum">     514 </span>                :     }
<span class="lineNum">     515 </span><span class="lineNoCov">              0 :   if (s.IsRandom()) return true; // Random seed is the default</span>
<span class="lineNum">     516 </span><span class="lineNoCov">              0 :   const ConstantSeed&amp; cs = (ConstantSeed&amp;)s;</span>
<span class="lineNum">     517 </span>                :   return GlobalSeed(cs.seeds[0], cs.seeds[1], cs.seeds[2],
<span class="lineNum">     518 </span><span class="lineNoCov">              0 :                     cs.seeds[3], cs.seeds[4], cs.seeds[5]);</span>
<span class="lineNum">     519 </span>                : }
<span class="lineNum">     520 </span>                : 
<span class="lineNum">     521 </span><span class="lineNoCov">              0 : void Random::Initialize()</span>
<span class="lineNum">     522 </span>                : { 
<span class="lineNum">     523 </span><span class="lineNoCov">              0 :   if (globalRNG) return; // Already initialized and seeded</span>
<span class="lineNum">     524 </span><span class="lineNoCov">              0 :   if (!globalSeedSet)</span>
<span class="lineNum">     525 </span>                :     { // No global seed, try a random one
<span class="lineNum">     526 </span><span class="lineNoCov">              0 :       GetRandomSeeds(globalSeed);</span>
<span class="lineNum">     527 </span>                :     }
<span class="lineNum">     528 </span>                :   // See the RNG package
<span class="lineNum">     529 </span>                :   //RngStream::SetPackageSeed(globalSeed); // No longer needed
<span class="lineNum">     530 </span>                :   // Create the base  RNG
<span class="lineNum">     531 </span><span class="lineNoCov">              0 :   globalRNG = new RngStream();</span>
<span class="lineNum">     532 </span><span class="lineNoCov">              0 :   globalRNG-&gt;SetSeed(globalSeed);</span>
<span class="lineNum">     533 </span>                : }
<span class="lineNum">     534 </span>                : #ifdef WIN32
<span class="lineNum">     535 </span>                : void          gettimeofday(struct timeval *tv,int dummy)
<span class="lineNum">     536 </span>                : {
<span class="lineNum">     537 </span>                : SYSTEMTIME SystemTime;
<span class="lineNum">     538 </span>                : GetSystemTime(&amp;SystemTime);
<span class="lineNum">     539 </span>                : tv-&gt;tv_sec = SystemTime.wSecond ;
<span class="lineNum">     540 </span>                : tv-&gt;tv_usec = SystemTime.wMilliseconds ;
<span class="lineNum">     541 </span>                : }
<span class="lineNum">     542 </span>                : 
<span class="lineNum">     543 </span>                : #endif
<span class="lineNum">     544 </span>                : 
<span class="lineNum">     545 </span><span class="lineNoCov">              0 : void Random::GetRandomSeeds(Seed_t seeds[6])</span>
<span class="lineNum">     546 </span>                : {
<span class="lineNum">     547 </span>                :   // Check if /dev/random exists
<span class="lineNum">     548 </span><span class="lineNoCov">              0 :   if (useDevRandom &amp;&amp; devRandom &lt; 0)</span>
<span class="lineNum">     549 </span>                :     {
<span class="lineNum">     550 </span>                : #ifndef WIN32   
<span class="lineNum">     551 </span><span class="lineNoCov">              0 :                 devRandom = open(&quot;/dev/random&quot;, O_RDONLY);</span>
<span class="lineNum">     552 </span>                : #endif
<span class="lineNum">     553 </span>                :     }
<span class="lineNum">     554 </span><span class="lineNoCov">              0 :   if (devRandom &gt; 0)</span>
<span class="lineNum">     555 </span>                :     { // Use /dev/random
<span class="lineNum">     556 </span>                :       DEBUG0((cout &lt;&lt; &quot;Seeding with /dev/random&quot; &lt;&lt; endl));
<span class="lineNum">     557 </span>                :       while(true)
<span class="lineNum">     558 </span>                :         {
<span class="lineNum">     559 </span><span class="lineNoCov">              0 :           for (int i = 0; i &lt; 6; ++i)</span>
<span class="lineNum">     560 </span>                :             {
<span class="lineNum">     561 </span>                : #ifndef WIN32
<span class="lineNum">     562 </span><span class="lineNoCov">              0 :               unsigned int size = read(devRandom, &amp;seeds[i], sizeof(seeds[i]));</span>
<span class="lineNum">     563 </span>                :               DEBUG0((cout &lt;&lt; &quot;Read &quot; &lt;&lt; size &lt;&lt; &quot; bytes&quot; &lt;&lt; endl));   
<span class="lineNum">     564 </span>                : #endif
<span class="lineNum">     565 </span>                :             }
<span class="lineNum">     566 </span><span class="lineNoCov">              0 :           if (RngStream::CheckSeed(seeds)) break; // Got a valid one</span>
<span class="lineNum">     567 </span>                :         }
<span class="lineNum">     568 </span>                :     }
<span class="lineNum">     569 </span>                :   else
<span class="lineNum">     570 </span>                :     { // Seed from time of day (code borrowed from ns2 random seeding)
<span class="lineNum">     571 </span>                :       // Thanks to John Heidemann for this technique
<span class="lineNum">     572 </span>                :       while(true)
<span class="lineNum">     573 </span>                :         {
<span class="lineNum">     574 </span>                : 
<span class="lineNum">     575 </span>                :           DEBUG0((cout &lt;&lt; &quot;Seeding with time of day&quot; &lt;&lt; endl));
<span class="lineNum">     576 </span>                :           timeval tv;
<span class="lineNum">     577 </span><span class="lineNoCov">              0 :           gettimeofday(&amp;tv, 0);</span>
<span class="lineNum">     578 </span>                :           seeds[0] = (tv.tv_sec^tv.tv_usec^(++heuristic_sequence &lt;&lt;8))
<span class="lineNum">     579 </span><span class="lineNoCov">              0 :               &amp; 0x7fffffff;</span>
<span class="lineNum">     580 </span><span class="lineNoCov">              0 :           gettimeofday(&amp;tv, 0);</span>
<span class="lineNum">     581 </span>                :           seeds[1] = (tv.tv_sec^tv.tv_usec^(++heuristic_sequence &lt;&lt;8))
<span class="lineNum">     582 </span><span class="lineNoCov">              0 :               &amp; 0x7fffffff;</span>
<span class="lineNum">     583 </span><span class="lineNoCov">              0 :           gettimeofday(&amp;tv, 0);</span>
<span class="lineNum">     584 </span>                :           seeds[2] = (tv.tv_sec^tv.tv_usec^(++heuristic_sequence &lt;&lt;8))
<span class="lineNum">     585 </span><span class="lineNoCov">              0 :               &amp; 0x7fffffff;</span>
<span class="lineNum">     586 </span><span class="lineNoCov">              0 :           gettimeofday(&amp;tv, 0);</span>
<span class="lineNum">     587 </span>                :           seeds[3] = (tv.tv_sec^tv.tv_usec^(++heuristic_sequence &lt;&lt;8))
<span class="lineNum">     588 </span><span class="lineNoCov">              0 :               &amp; 0x7fffffff;</span>
<span class="lineNum">     589 </span><span class="lineNoCov">              0 :           gettimeofday(&amp;tv, 0);</span>
<span class="lineNum">     590 </span>                :           seeds[4] = (tv.tv_sec^tv.tv_usec^(++heuristic_sequence &lt;&lt;8))
<span class="lineNum">     591 </span><span class="lineNoCov">              0 :               &amp; 0x7fffffff;</span>
<span class="lineNum">     592 </span><span class="lineNoCov">              0 :           gettimeofday(&amp;tv, 0);</span>
<span class="lineNum">     593 </span>                :           seeds[5] = (tv.tv_sec^tv.tv_usec^(++heuristic_sequence &lt;&lt;8))
<span class="lineNum">     594 </span><span class="lineNoCov">              0 :               &amp; 0x7fffffff;</span>
<span class="lineNum">     595 </span><span class="lineNoCov">              0 :           if (RngStream::CheckSeed(seeds)) break; // Got a valid one</span>
<span class="lineNum">     596 </span>                :         }
<span class="lineNum">     597 </span>                :     }
<span class="lineNum">     598 </span><span class="lineCov">              2 : }</span>
<span class="lineNum">     599 </span>                : 
<span class="lineNum">     600 </span>                :   
<span class="lineNum">     601 </span>                : 
</pre>
      </td>
    </tr>
  </table>
  <br>

  <table width="100%" border=0 cellspacing=0 cellpadding=0>
  <tr><td class="ruler"><img src="../../glass.png" width=3 height=3 alt=""></td></tr>
  <tr><td class="versionInfo">Generated by: <a href="http://ltp.sourceforge.net/coverage/lcov.php" target="_parent">LTP GCOV extension version 1.6</a></td></tr>
  </table>
  <br>

</body>
</html>
